﻿using System.Configuration;
using System.Globalization;

namespace ManagedUIFlow.Infrastructure.Flows.Configuration
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1010:CollectionsShouldImplementGenericInterface"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1010:CollectionsShouldImplementGenericInterface")]
    public class FlowConfigurationElementCollection : ConfigurationElementCollection
    {
        [ConfigurationProperty("of", IsRequired = true)]
        public string Flow
        {
            get { return (string)base["of"]; }
            set { base["of"] = value; }
        }

        [ConfigurationProperty("beginsWith", IsRequired = false)]
        public string Initiate
        {
            get { return (string)base["beginsWith"]; }
            set { base["beginsWith"] = value; }
        }        

        [ConfigurationProperty("redirectable", IsRequired = false)]
        public RedirectBehavior Redirectable
        {
            get { return (RedirectBehavior)base["redirectable"]; }
            set { base["redirectable"] = value; }
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1056:UriPropertiesShouldNotBeStrings"), ConfigurationProperty("url", IsRequired = false)]
        public string RedirectUrl
        {
            get { return (string)base["url"]; }
            set { base["url"] = value; }
        }      

        protected override bool ThrowOnDuplicate
        {
            get { return true; }
        }

        public void Add(GivenConfigurationElementCollection render)
        {
            BaseAdd(render);
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods")]
        public bool Contains(string renderName)
        {
            return base.BaseGet(renderName.ToLower(CultureInfo.CurrentCulture)) != null;
        }

        public override ConfigurationElementCollectionType CollectionType
        {
            get { return ConfigurationElementCollectionType.BasicMap; }
        }

        protected override string ElementName
        {
            get { return "given"; }
        }

        protected override ConfigurationElement CreateNewElement()
        {
            return new GivenConfigurationElementCollection();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((GivenConfigurationElementCollection)element).Name.ToLower(CultureInfo.CurrentCulture);
        }

        public GivenConfigurationElementCollection this[int index]
        {
            get { return (GivenConfigurationElementCollection)base.BaseGet(index); }
        }

        public new GivenConfigurationElementCollection this[string navigationGraphName]
        {
            get
            {
                return (GivenConfigurationElementCollection)base.BaseGet(navigationGraphName.ToLower(CultureInfo.CurrentCulture));
            }
        }
    }
}